﻿#pragma once

#include "World/World.h"
#include "World/Direction.h"

struct HitTarget
{
  glm::ivec3 blockPosition;
  glm::ivec3 neighborPosition;
  bool hasNeighbor{false};
  BlockData *block{nullptr};
  Block *blockType{nullptr};
  uint8_t face{Direction::None};
};

class AppContext;

class CORE_API WorldRayCast
{
public:
  WorldRayCast(const glm::vec3 &start, const glm::vec3 &end, World &world);
  WorldRayCast(const glm::vec3 &start, const glm::vec3 &direction, float reach, World &world);

  bool HasHit() const { return m_successful; };
  HitTarget GetHitTarget() const { return m_hitTarget; };
  explicit operator bool() const { return HasHit(); }

private:
  void Do();

  World &m_world;

  glm::vec3 m_start{0.0f};
  glm::vec3 m_end{0.0f};

  bool m_successful{false};
  HitTarget m_hitTarget{};
};